home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / listbox / lstgrid / griddd.frm (.txt) next >
Encoding:
Visual Basic Form  |  1994-02-11  |  3.0 KB  |  93 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Drag Drop on the Grid"
  4.    ClientHeight    =   2850
  5.    ClientLeft      =   1575
  6.    ClientTop       =   1590
  7.    ClientWidth     =   7470
  8.    Height          =   3255
  9.    Left            =   1515
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   2850
  12.    ScaleWidth      =   7470
  13.    Top             =   1245
  14.    Width           =   7590
  15.    Begin ListBox List1 
  16.       Height          =   2565
  17.       Left            =   0
  18.       TabIndex        =   1
  19.       Top             =   0
  20.       Width           =   2415
  21.    End
  22.    Begin Grid Grid1 
  23.       Cols            =   20
  24.       Height          =   2655
  25.       Left            =   2400
  26.       Rows            =   20
  27.       TabIndex        =   0
  28.       Top             =   0
  29.       Width           =   5055
  30.    End
  31. 'Dragging is a flag used for each control to determine
  32. 'if we are dragging something.
  33. Dim dragging As Integer
  34. Sub Form_Load ()
  35. For X = 1 To 10
  36.    list1.AddItem X
  37. Next X
  38. End Sub
  39. Sub Grid1_DragDrop (Source As Control, X As Single, Y As Single)
  40. 'Calculate the row to drop in.  Add each row until we pass Y
  41. 'All this is calculated in twips.
  42. currentrow = grid1.TopRow
  43. twipcount = grid1.RowHeight(currentrow)
  44. While (twipcount <= Y)
  45.    currentrow = currentrow + 1
  46.    twipcount = twipcount + grid1.RowHeight(currentrow)
  47.    'If there are gridlines, we have to add those in too
  48.    If grid1.GridLines Then
  49.       twipcount = twipcount + grid1.GridLineWidth * screen.TwipsPerPixelY
  50.    End If
  51. 'Calculate the column to drop in.  Add each row until we pass X
  52. 'All this is calculated in twips.
  53. currentcol = grid1.LeftCol
  54. twipcount = grid1.ColWidth(currentcol)
  55. While (twipcount <= X)
  56.    currentcol = currentcol + 1
  57.    twipcount = twipcount + grid1.ColWidth(currentcol)
  58.    'If there are gridlines, we have to add those in too
  59.    If grid1.GridLines Then
  60.       twipcount = twipcount + grid1.GridLineWidth * screen.TwipsPerPixelX
  61.    End If
  62. 'Assign value
  63. grid1.Col = currentcol - 1
  64. grid1.Row = currentrow - 1
  65. grid1.Text = list1.Text
  66. 'End drag mode
  67. list1.Drag 2
  68. dragging = False
  69. End Sub
  70. Sub List1_DragDrop (Source As Control, X As Single, Y As Single)
  71. 'Ooops.  Dropped on ourselves.  Just cancel the drag mode.
  72. list1.Drag 0
  73. dragging = False
  74. End Sub
  75. Sub List1_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  76. 'If the mouse goes down, set the dragging flag in case this is for a drag
  77. dragging = True
  78. End Sub
  79. Sub List1_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  80. 'If the dragging flag was set, then we will enable the drag
  81. 'MouseDown has to set the flag first
  82. If dragging Then
  83.    dragging = False  'Cancel the flag
  84.    list1.Drag 1      'Start the drag mode
  85.    list1.Drag 0      'Cancel if flag was not set
  86. End If
  87. End Sub
  88. Sub List1_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  89. 'Mouse released on text box so cancel the dragging mode
  90. list1.Drag 0
  91. dragging = False
  92. End Sub
  93.